package webapp;

import java.io.IOException;
import java.io.PrintStream;

import com.dao.MenbersDao;
import com.util.Page;

import ejw.ServerInterface;
import ejw.utilities.StringUtils;

/**
 * 会员管理
 * @author tiger
 *
 */
public class Menbers extends BaseHandler {
	public String get(ServerInterface serverInterface, String[] args) {
		print(System.out, "GET", args, serverInterface.getServletRequest().getQueryString());
		request().getQueryString();
		setAttribute("method", "GET");
		setAttribute("args", StringUtils.toString(args));
		setAttribute("data", request().getQueryString());

		return "/WEB-INF/response2.jsp";
	}

	public String post(ServerInterface serverInterface, String[] args) {
		print(System.out, request().getMethod(), args, getParameter("value"));

		setAttribute("method", request().getMethod());
		setAttribute("args", StringUtils.toString(args));
		setAttribute("data", getParameter("value"));
		Page page = new Page();
		try {
			page = menbersDao.findbyPage(page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		setAttribute("page", page);
		return "/WEB-INF/response2.jsp";
	}

	public String put(ServerInterface serverInterface, String[] args) {
		post(serverInterface, args);

		return NO_FORWARDING;
	}

	public String delete(ServerInterface serverInterface, String[] args) throws IOException {
		String body = request().getReader().readLine();

		print(System.out, "DELETE", args, body);

		response().setContentType("text/plain");

		PrintStream out = new PrintStream(response().getOutputStream());
		print(out, "DELETE", args, body);

		return NO_FORWARDING;
	}

	void print(PrintStream out, String method, String[] args, String body) {
		out.println("processing " + method);
		out.println("args = " + StringUtils.toString(args));
		out.println("body = " + body);
	}
	private MenbersDao menbersDao = (MenbersDao) ioc.newInstance(MenbersDao.class);
}
